package com.rfid.a252robot.admin.adapter;

import android.hardware.usb.UsbDevice;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.rfid.a252robot.R;
import com.rfid.a252robot.base.BaseAdapter;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class UsbDeviceAdapter extends BaseAdapter<UsbDeviceAdapter.ViewHolder, UsbDevice> {


    public UsbDeviceAdapter(List<UsbDevice> data) {
        super(data);
    }

    @Override
    protected void bindView(ViewHolder holder, int position) {
        UsbDevice device = mData.get(position);
        holder.pid.setText("PID:" + Integer.toHexString(device.getProductId()));
        holder.vid.setText("VID:" + Integer.toHexString(device.getVendorId()));
        holder.serialNumber.setText("序列号：" + device.getSerialNumber());
        holder.name.setText(device.getDeviceName());
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_usb_device,parent,false));
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.name)
        TextView name;
        @BindView(R.id.pid)
        TextView pid;
        @BindView(R.id.vid)
        TextView vid;
        @BindView(R.id.serialNumber)
        TextView serialNumber;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
